package com.itcast.controller;

import com.itcast.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {

    @Autowired
    private RedisService redisService;

    /**
     * 获取店铺库存
     * @param shopId
     * @return
     */
    @GetMapping("queryStock/{shopId}")
    public Integer queryStock(@PathVariable Integer shopId){
        return redisService.queryStock(shopId);
    }

    /**
     * 超卖问题
     * @param shopId
     */
//    @PutMapping("secKill/{shopId}")
//    public void secKill(@PathVariable Integer shopId){
//        redisService.secKill(shopId);
//    }

    /**
     * 一人一单问题
     * @param shopId
     * @param userId
     * @return
     */
    @PutMapping("secKill/{shopId}/{userId}")
    public String secKill(@PathVariable Integer shopId,@PathVariable Integer userId){
        return redisService.secKill(shopId,userId);
    }
}
